using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SPSAndong.Entity;
using SPSAndong.Model;
using Leeder.Service;
using Leeder.Repository;

namespace SPSAndong.Service
{
    /// <summary>
    /// 
    /// </summary>
   public class CallDetailsService : BaseService<CallDetailsModel>
   {
        /// <summary>
        /// 关联实体类型
        /// </summary>
        protected override Type RefEntityType { get { return typeof(CallDetailsEntity); } }

        /// <summary>
        /// 根据条件获取数据总量
        /// </summary>
        /// <param name="where">查询条件</param>
        /// <returns></returns>
        public int GetPartsCountByWhere(string where)
        {
            return RF<CallDetailsEntity>.SqlQueryable("SELECT  * FROM CallDetails " + where).Count();
        }

        public List<CallDetailsModel> GetModelListByPage(string where, int pageIndex, int pageSize)
        {
            if (pageIndex < 1)
                return null;
            pageIndex = (pageIndex - 1) * pageSize;
            var sql = "SELECT  * FROM CallDetails " + where + " ORDER BY CreateTime DESC OFFSET " + pageIndex + " ROWS FETCH NEXT " + pageSize + " ROWS ONLY";
            return RF<CallDetailsEntity>.SqlQueryable(sql).Select(s => new CallDetailsModel
            {
                ID = s.ID,
                AreaType = s.AreaType,
                AreaName = s.AreaName,
                ProjectName = s.ProjectName,
                CreateTime = s.CreateTime,
                ResponseTime = s.ResponseTime
            }).ToList();
        }
    }
}